package com.kgc.book.bookweb.controller;


import com.kgc.book.config.ResultEntity;
import com.kgc.book.entity.Bookmanager;
import com.kgc.book.service.BookmanagerService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CQW
 * @since 2020-10-03
 */
@Controller
public class BookmanagerController {

    @Reference
    BookmanagerService bookmanagerService;

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Bookmanager> selectAll(){
        List<Bookmanager> bookmanagers = bookmanagerService.selectAllBook();
        return bookmanagers;
    }
    @RequestMapping("/delBook")
    @ResponseBody
    public ResultEntity<String> delBook(Integer bId){
        Integer i = bookmanagerService.delBook(bId);

        return ResultEntity.successWithoutData(i+"");
    }
    @RequestMapping("/saveBook")
    @ResponseBody
    public Map<String,Object> save(@RequestBody Bookmanager bookmanager){
        Map<String,Object> map=new HashMap<>();
        int i = bookmanagerService.saveBook(bookmanager);
        if (i>0){
            map.put("result","success");
            return map;
        }else {
            map.put("data","error");
            return map;
        }
    }
}
